// jsproxy.js
const fs = require('fs');
const path = require('path');
const { BaseProxy } = require('../_base_/base');

class JsProxy extends BaseProxy {
    // 读取模型的配置文件列表
    loadConfigList() {
        try {
            let configs_path = path.join(__dirname, 'model_infos', 'model.list');
            const listData = fs.readFileSync(configs_path, 'utf8');
            const lines = listData
                .split('\n')
                .map((line) => line.trim())
                .filter((line) => line);
            // console.log(lines);
            return lines;
        } catch (error) {
            console.error(error);
            return [];
        }
    }

    // 读取模型结构
    loadModelArch(config_name) {
        try {
            let config_path = path.join(__dirname, 'model_infos', 'arch', config_name + '.json');
            const jsonData = fs.readFileSync(config_path, 'utf8');
            const jsonArch = JSON.parse(jsonData);
            return jsonArch;
        } catch (error) {
            console.error(error);
        }
    }

    // 读取模型参数
    loadModelParams(config_name) {
        try {
            let config_path = path.join(__dirname, 'model_infos', 'params', config_name + '.json');
            const jsonData = fs.readFileSync(config_path, 'utf8');
            const jsonArch = JSON.parse(jsonData);
            return jsonArch;
        } catch (error) {
            console.error(error);
        }
    }
}
module.exports = JsProxy;
